import React, { Component } from 'react'
import axios from "axios";
import style from "../components/list.module.css";

const stateObj = {
  "onSale": "在售",
  "forSale": "待售",
  "soldOut": "售完",
  "newCom": "新楼盘"
}

export class Detail extends Component {
  constructor(props) {
    super(props)

    this.state = {
      detail: {} //从后端找到id一致的那项
    }
  }

  componentDidMount() {
    axios.get("/getdetail", {
      params: {
        id: this.props.match.params.id
      }
    }).then(res => {
      console.log(res);
      this.setState({
        detail: res.data
      })
    })
  }

  render() {
    const { detail } = this.state;
    // console.log("详情", this);
    return (
      <div>
        
        <img src={detail.img} alt="" />
        <h3>{detail.title}</h3>
        <p>{detail.price}</p>
        <button className={style[detail.state]}>{stateObj[detail.state]}</button>
      </div>
    )
  }
}

export default Detail